package cn.zxh.improvement.common.core.function;

import cn.zxh.improvement.common.core.utils.Exceptions;

/**
 * 提供商函数
 *
 * @author zxh
 * @since 2023/4/26 15:42:22
 */
@FunctionalInterface
public interface SupplierWithException<T> extends java.util.function.Supplier<T> {

    /**
     * 获取结果
     *
     * @return object
     */
    @Override
    default T get() {
        try {
            return getWithException();
        } catch (Throwable e) {
            throw Exceptions.toRuntime(e);
        }
    }

    /**
     * 获取实例，如果发生异常要抛出异常
     *
     * @return object
     * @throws Throwable - 抛出引发的任何异常
     */
    T getWithException() throws Throwable;
}
